package com.zhang.dft_project.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用返回请求
 */
@Data
@AllArgsConstructor
@NoArgsConstructor

public class R {
    private Integer code;
    private String msg;
    private String data = "";

    public R(Integer code, String msg) {


        this.code = code;
        this.msg = msg;
    }


    public R(ResultEnum result, String data) {
        this.code = result.code;
        this.msg = result.msg;
        this.data = data;
    }
    public void setResultEnum(ResultEnum resultEnum){
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public static R ok(ResultEnum result, String data) {
        R r = new R();
        r.setResultEnum(result);
        r.setData(data);
        return r;
    }

    public static R ok(ResultEnum result) {
        R r = new R();
        r.setResultEnum(result);
        return r;
    }

}
